#include "pch.h"
#include "simple.h"
#include "kmp.h"

//#define StrMatchImpl SimpleMatch
#define StrMatchImpl KMPMatch

void PrintTest(std::string_view target, std::string_view pattern,
               std::string::size_type found_pos) {
  if (std::string::npos == found_pos) {
    std::cout << pattern << " is not in " << target << std::endl;
  } else {
    std::cout << "found pos " << found_pos << " " << target.data() + found_pos
              << std::endl;
  }
  std::cout << std::endl;
}

void Test1() {
  std::string target(20, 'a');
  std::string pattern{"aab"};

  auto found_pos = StrMatchImpl(target, pattern);
  PrintTest(target, pattern, found_pos);
}

void Test2() {
  std::string target{R"(
j7bVDo5w0m6zhmQBHMtM5WksUnrhRAg6yYZY1EM5zxbgvyHePXs2aGVZEVU5OlCNSrlYzwb4
338gkwY1kwld8FUdsHKY52YJl9OU9n5VP2NS8wSJvXtTXf73u0R3vnQSmAWZ6ZEiv3WD1JeA
71bCVL4VUu3SkiImG1Jc1usUrX3t8hw0SbxMAPM2LpMrHqDc1qVhgch3lGHcL3Huk98gtHQy
MfwxgSsPpQhNFBh4pxDZn3a876YXiMoq3BPrTtUpBSjP9LPLQSDrZH27CuhtP5f1OyX7Rznb
QUzwoHGyYdfYJqxW3tOWM2VFIkdIeafMIaE50FwTKGTNwFEvAd2Deit2GY5onpplpSlOJV5k
tExphXJhrVm5480a0VxoqDdeEvgjXX2XNN5u3ybtBHKmGUUQcNfWdJLI4hA7sZ8HAKxuqoFp
10thianwxza2aZFcEXlY9ZZQyn2nOUKC053t4pWsKG2EFgu1Y4Fva1dGWLZV0qt4fXSrbOBz
x3pXdfMmaIBxFwbtlUcksrcLA7Mx4cdhNO3OQqyybx0ZjiKWqbJX4wGwd5ee4ECuhykqlMsC
2jZqbEGI9d3rbwYk3FpNYA6O9kHSes8ihcNyzvBCOrd9xVgEmtCIyzfKJOhShzwiMl2SzuFN
hekeHf6FMQOIJOufeEVjFlPPEQUtTSBEWUkMNhLYFbYS9XeTwkyR4GgNPS5fAuQhRgqrDd4f
UA0GHYyNytmKzWoAzzA6aZUFMFVLrncXDygP5vcMMULdRwVeSgL8USUM3jsY7Gwba710APIj
sJAI8VqU2xiudhEKK7nvXKeAoMkSZuRJEVRMsuZdptwgRgSH9rXDeJlGTJ69L00sjn9KIeq4
oOjAkcT55Bh8BOftJTy45zNKHTKQMS0udxA870Shw3z6Um1lsAQF9tJOzT3UWEgy1GJd2ppr
ew8spnpCEk4CzlhAUNzDPXJttCQxRBTO7IKR3UZKy0Rr9U8rCbizAm0z1GqUucuz")"};
  std::string pattern{"3rbwYk3"};

  auto found_pos = StrMatchImpl(target, pattern);
  PrintTest(target, pattern, found_pos);
}

void Test3() {
  std::string target{
      "abababababababababababababababababababababababababababababababababababab"
      "abababababababababababababababababababababababababababababababababababab"
      "abababababababababababababababababababababababababababababababababababab"
      "abababababababababababababababababababababababababababababababababababab"
      "ccabababccabababccabababababababababababababababababababababababababab"};
  std::string pattern{"ababababababccabababccabababcc"};

  auto found_pos = StrMatchImpl(target, pattern);
  PrintTest(target, pattern, found_pos);
}

void Test4() {
  std::string target{"bacbababaabcbab"};
  std::string pattern{"ababaca"};

  auto found_pos = StrMatchImpl(target, pattern);
  PrintTest(target, pattern, found_pos);
}

void Test5() {
  std::string target{"bacbababaabcbaababacab"};
  std::string pattern{"ababaca"};

  auto found_pos = StrMatchImpl(target, pattern);
  PrintTest(target, pattern, found_pos);
}

int main(int argc, char *argv[]) {
  Test1();
  Test2();
  Test3();
  Test4();
  Test5();
  return 0;
}
